package value

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object mapPartitionsWithIndex {
  def main(args: Array[String]): Unit = {
    //1.创建SparkConf并设置App名称
    val conf = new SparkConf().setAppName("SparkCoreTest").setMaster("local[*]")

    //2.创建SparkContext，该对象是提交Spark App的入口
    val sc = new SparkContext(conf)

    val value: RDD[Int] = sc.makeRDD(1 to 5,2)

    val indexRDD: RDD[(Int, Int)] = value.mapPartitionsWithIndex((index,num) => {num.map((index,_))})

    indexRDD.collect().foreach(println)

    //关闭
    sc.stop()

  }

}
